package com.example.demo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class MyImageView extends ImageView {

    Path path =  new Path();
    Paint paint = new Paint();
    public MyImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(5);
        paint.setDither(true);
        paint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawPath(path,paint);

    }

    public void showFace(Location location) {
        int left = (int) location.getLeft();
        int top  = (int) location.getTop();
        int width = location.getWidth();
        int height = location.getHeight();
        Point p1 = new Point(left, top);
        Point p2 = new Point(left+ width, top);
        Point p3 = new Point(left, top+height);
        Point p4 = new Point(left+ width, top+height);
        path.reset();
        path.moveTo(p1.x, p1.y);
        path.lineTo(p2.x, p2.y);
        path.lineTo(p4.x, p4.y);
        path.lineTo(p3.x, p3.y);
        path.lineTo(p1.x, p1.y);
        invalidate();
    }
}
